const express = require('express')
const router = express.Router()
const db = require('../../db/conn_blog')

router.get('/', async (req, res, next) => {
  let articles = await db.getArticle().catch(err => err)

  if (articles === 'DATABASE ERROR, connection failed!')
    articles = []

  res.render('index', { articles })
})

module.exports = router